{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "2626ff10-4407-4900-a7ea-f0bfc77c9799",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 20\n"
     ]
    }
   ],
   "source": [
    "a, b = 10, 20\n",
    "print(a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "cb399d39-ff61-48e8-a4be-b9453fc27793",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f8ef70ce-fb02-4694-a803-311665448dc2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 20\n"
     ]
    }
   ],
   "source": [
    "a, b = [10, 20]\n",
    "print(a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e0f0c17d-d0e8-48db-98f3-7f866f0c818a",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "53fbbd7f-ba00-454a-a568-d2cf6f8d9f2e",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "not enough values to unpack (expected 2, got 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m a, b \u001b[38;5;241m=\u001b[39m [\u001b[38;5;241m10\u001b[39m]\n",
      "\u001b[0;31mValueError\u001b[0m: not enough values to unpack (expected 2, got 1)"
     ]
    }
   ],
   "source": [
    "a, b = [10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "43c8bbcb-4c88-42bb-bb9f-4601680e8f30",
   "metadata": {},
   "outputs": [
    {
     "ename": "ValueError",
     "evalue": "too many values to unpack (expected 2)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[0;31mValueError\u001b[0m                                Traceback (most recent call last)",
      "Cell \u001b[0;32mIn[4], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m a, b \u001b[38;5;241m=\u001b[39m \u001b[38;5;241m10\u001b[39m, \u001b[38;5;241m20\u001b[39m, \u001b[38;5;241m30\u001b[39m\n",
      "\u001b[0;31mValueError\u001b[0m: too many values to unpack (expected 2)"
     ]
    }
   ],
   "source": [
    "a, b = 10, 20, 30"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "63859b3c-d2e1-4331-ade8-7a432bb24968",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "6a725897-615c-4328-a5a4-df24f38a2ae3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "20 10\n"
     ]
    }
   ],
   "source": [
    "a, b = 10, 20\n",
    "a, b = b, a # 解构赋值，交换a和b\n",
    "\n",
    "print(a, b)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "4fe03170-d823-4396-b966-003e6be6f20e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "aa0bc14c-ad9c-4e72-9cf5-c66e099ac778",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(20, 30, 10)"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "a, b, c = 10, 20, 30\n",
    "a, b, c = b, c, a # 左移循环交换\n",
    "a, b, c"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "03301f01-111b-41fc-b3c1-b610a81872ec",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9ea3c561-f507-484a-88f1-11c26ac3d954",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 40\n"
     ]
    }
   ],
   "source": [
    "head, _, _, tail = [10, 20, 30, 40]\n",
    "print(head, tail)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "0b3b0419-6ebf-41da-9026-06dedf74bcd8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 [20, 30, 40, 50]\n"
     ]
    }
   ],
   "source": [
    "head, *others = [10, 20, 30, 40, 50]\n",
    "print(head, others)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "5e862e83-5693-4428-beb2-905e1c4ba551",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10 50\n"
     ]
    }
   ],
   "source": [
    "head, *_, tail = [10, 20, 30, 40, 50]\n",
    "print(head, tail)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52153ec8-7d68-4dc4-8d5e-3a777d754992",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "id": "50d8bd6a-5a2e-4b22-aa7a-8f16fc03c410",
   "metadata": {},
   "source": [
    "<br>\n",
    "星号匹配只能出现一次"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e5768a77-accb-423a-8e17-5a8ec7356593",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "multiple starred expressions in assignment (2825470343.py, line 1)",
     "output_type": "error",
     "traceback": [
      "\u001b[0;36m  Cell \u001b[0;32mIn[10], line 1\u001b[0;36m\u001b[0m\n\u001b[0;31m    a, *b, c, *c = [10, 20, 30, 40, 50]\u001b[0m\n\u001b[0m    ^\u001b[0m\n\u001b[0;31mSyntaxError\u001b[0m\u001b[0;31m:\u001b[0m multiple starred expressions in assignment\n"
     ]
    }
   ],
   "source": [
    "a, *b, c, *c = [10, 20, 30, 40, 50]\n",
    "print(a, b, c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9126c7b1-2864-4ba6-ae33-1de741862d44",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "af5d362c-0767-4e8f-878b-f7ad47f0591e",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "94f98cf0-f6ab-4612-80d6-810fa6b0c7c0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "第一个： 201 张三\n",
      " 其他： [(202, '李四'), (203, '王五')]\n"
     ]
    }
   ],
   "source": [
    "(学号, 姓名), *others = [(201, '张三'), (202, '李四'), (203, '王五')]\n",
    "print('第一个：', 学号, 姓名)\n",
    "print(' 其他：', others)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
